<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        甲供件-毛坯与铝料单据冲单
    </h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>
                                        出入库类别
                                    </label>
                                    <select id="odrType" name="odrType" class="form-control">
                                        <option value="1" selected="selected">入库</option>
                                        <option value="2">出库</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>单据编号</label>
                                    <input type="text" id="odrCode" name="odrCode"
                                           class="form-control"
                                           placeholder="请输入单据编号">
                                </div>
                                <div class="form-group">
                                    <label>制单人</label>
                                    <input type="text" id="odrTakePerson" name="odrTakePerson"
                                           class="form-control"
                                           placeholder="请输入制单人">
                                </div>
                                <div class="form-group">
                                    <label>物料描述</label>
                                    <input type="text" id="odaMatName" name="odaMatName"
                                           class="form-control"
                                           placeholder="请输入物料描述">
                                </div>
                                <div class="form-group">
                                    <label>规格</label>
                                    <input type="text" id="odaSpec" name="odaSpec"
                                           class="form-control"
                                           placeholder="请输入规格">
                                </div>
                                <div class="form-group">
                                    <label>图号</label>
                                    <input type="text" id="odaDrawingCode" name="odaDrawingCode"
                                           class="form-control"
                                           placeholder="请输入图号">
                                </div>
                                <!--<div class="form-group">-->
                                <!--<label>SAP物料编码</label>-->
                                <!--<input type="text" id="odaSapCode" name="odaSapCode"-->
                                <!--class="form-control"-->
                                <!--placeholder="请输入SAP物料编码">-->
                                <!--</div>-->
                                <!--<div class="form-group">-->
                                <!--<label>跟踪号</label>-->
                                <!--<input type="text" id="odaTrackCode" name="odaTrackCode"-->
                                <!--class="form-control"-->
                                <!--placeholder="请输入跟踪号">-->
                                <!--</div>-->
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" id="odaProCode" name="odaProCode"
                                           class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" id="odaProName" name="odaProName"
                                           class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>部分名称</label>
                                    <input type="text" id="odaPart" name="odaPart"
                                           class="form-control"
                                           placeholder="请输入部分名称">
                                </div>
                                <div class="form-group">
                                    <label>
                                        单据类型
                                    </label>
                                    <select id="odrOutType" name="odrOutType" class="form-control">
                                        <option value="" selected="selected">入库全部</option>
                                        <option value="1">采购入库</option>
                                        <option value="2">返料入库</option>
                                    </select>
                                </div>
                                <!--<div class="form-group">-->
                                <!--<label>存放状态</label>-->
                                <!--<select id="odaMakingPiecesStatus" name="odaMakingPiecesStatus" class="form-control">-->
                                <!--<option value="" selected="selected">全部</option>-->
                                <!--<option value="待机加">待机加</option>-->
                                <!--<option value="待外协">待外协</option>-->
                                <!--<option value="待装配">待装配</option>-->
                                <!--<option value="待发货">待发货</option>-->
                                <!--<option value="临时存放">临时存放</option>-->
                                <!--</select>-->
                                <!--</div>-->
                                <div class="form-group">
                                    <label>
                                        红冲过滤
                                    </label>
                                    <select id="odaRedFlag" name="odaRedFlag" class="form-control">
                                        <option value="0" selected="selected">不显示红冲</option>
                                        <option value="1">只显示红冲</option>
                                        <option value="">全部</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>库位</label>
                                    <select id="odaWhiId" name="odaWhiId" class="form-control">
                                        <option value="">全部</option>
                                        <option th:each="type:${warInfo}" th:value="${type.whiId}"
                                                th:text="${type.whiName}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>记账日期</label>
                                    <input type="text" class="form-control datepicker" id="startStorageDate"
                                           name="startStorageDate" readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" id="endStorageDate"
                                           name="endStorageDate" readonly="readonly"/>
                                </div>
                                <div class="form-group">
                                    <label>制单时间</label>
                                    <input type="text" class="form-control datepicker" id="startOdrMakeDate"
                                           name="startOdrMakeDate" readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" id="endOdrMakeDate"
                                           name="endOdrMakeDate" readonly="readonly"/>
                                </div>
                                <div class="form-group" >
                                    <button type="button" class="btn btn-success" id="btn-search">搜索</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="toolbar">
                    <button shiro:hasPermission="jiagong:semiandaluiminumoffset:edit" type="button"
                            class="btn btn-danger pull-right"
                            id="btn-togetherRed">
                        批量红冲
                    </button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"  style="word-break:break-all; word-wrap:break-all;"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>

<script th:inline="javascript">

    /**加载表格*/
    var table;

    /** 单条红冲 */
    function toRed(row) {
        if(row.odrOutType == 3){
            js.modal.warning("调拨入库需要批量红冲！！")
        }else {
            js.modal.confirm("确定要红冲该条明细吗？", function (result) {
                js.post({
                    url: ctx + "offset/toRed",
                    data: {
                        odaId: row.odaId
                    },
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                            js.table.refresh(table);
                        } else {
                            js.modal.warning(result.msg);
                            js.table.refresh(table);
                        }
                        js.modal.closeLoading();
                    }
                })
            })
        }
    }

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "offset/list",
            pageSize: 300,
            columns: [
                {
                    field: "checked",
                    title: '全选',
                    checkbox: true,
                    formatter: function (value, row, index) {
                        if (row.odaRedFlag === 1) {
                            return {
                                disabled: true
                            }
                        } else {
                            return {
                                disabled: false
                            }
                        }
                    }
                },
                {title: '调拨单号', field: 'odrRepId',visible: false},
                {
                    title: '序号', field: 'odaId', width: '40',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '单据类型', field: 'odrOutType',
                    formatter: function (value, row, index) {
                        if (row.odrOutType == 1) {
                            return "采购入库"
                        } else if (row.odrOutType == 2) {
                            return "返料入库"
                        } else if (row.odrOutType == 3) {
                            return "调拨入库"
                        } else if(row.odrOutType == 4){
                            return "领料出库"
                        }else if (row.odrOutType == 7) {
                            return "发货出库"
                        } else if(row.odrOutType == 8){
                            return "生产入库"
                        } else {
                            return row.odrOutType
                        }
                    }
                },
                {title: '单据编号', field: 'odrCode'},
                {title: '物料描述<br>（铝料类型）', field: 'odaMatName'},
                {title: '规格', field: 'odaSpec'},
                {title: '图号<br>（铝料模具号）', field: 'odaDrawingCode'},
                // {title: 'SAP<br>物料编码', field: 'odaSapCode'},
                {title: '数量', field: 'odaNum'},
                {title: '单位', field: 'odaUnit'},
                // {title: '跟踪号', field: 'odaTrackCode',width:'110'},
                {title: '项目编号', field: 'odaProCode', width: '90'},
                {title: '项目名称', field: 'odaProName'},
                {title: "合同编号", field: 'contractNo', width: '90'},
                {title: "供应商", field: 'odaSupplier', width: '90'},
                {title: '部分名称', field: 'odaPart'},
                // {title: '存放状态', field: 'odaMakingPiecesStatus'},
                //{title: '部分名称', field: 'odaPart'},
                {title: '库位', field: 'odaWhiIdName',width:'60'},
                /*{
                    title: '在库类型', field: 'odaStockType',
                    formatter: function (value, row, index) {
                        if (row.odaStockType == 1) {
                            return "库存在库"
                        } else if (row.odaStockType == 2) {
                            return "项目在库"
                        } else {
                            return row.odaStockType
                        }
                    }
                },*/
                {title: '记账日期', field: 'odaStorageDate', width: '90'},
                {title: '制单时间', field: 'odrDate', width: '90'},
                {title: '制单人', field: 'odrTakePerson', width: '60'},
                {title: '操作', width: '60',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP("jiagong:semiandaluiminumoffset:edit") && row.odaRedFlag == 0) {
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="toRed(' + js.jsonStringify(row) + ')"> 红冲</a>');
                        }
                        return actions.join('');
                    }}
            ],
            rowStyle: function (row, index) {
                if (row.odaRedFlag === 1) {
                    return {css: {"color": "red"}}
                } else {
                    return {css: {"color": "black"}}
                }
            }
        });

        /** 表格搜索 */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /** 出入库类别改变 联动单据类型 */
        $("#odrType").change(function () {
            if ($("#odrType").val() == 1) {
                // 1出库
                $("#odrOutType").empty().append('<option value="">入库全部</option>').append('<option value="8">生产入库</option>').append('<option value="2">返料入库</option>').append('<option value="1">采购入库</option>');
            } else if ($("#odrType").val() == 2) {
                // 2出库
                $("#odrOutType").empty().append('<option value="">出库全部</option>').append('<option value="4">领料出库</option>').append('<option value="7">发货出库</option>');
            }
        })

        /** 批量红冲 */
        $("#btn-togetherRed").click(function () {
            var rows = js.table.selectRows("bootstrap-table");
            // 如果没有选择，显示提示信息
            if (rows.length < 2 && rows[0].odrOutType != 3) {
                js.modal.warning("请至少选择两条明细！");
                return false;
            } else {
                js.post({
                    url: ctx + "offset/toRedTogether",
                    contentType: "application/json",
                    data: JSON.stringify(rows),
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success("操作成功");
                            js.table.refresh(table);
                        } else {
                            js.modal.warning(result.msg);
                            js.table.refresh(table);
                        }
                        js.modal.closeLoading();

                    }
                })
            }
        });

        $('#queryHiddenDiv').on('show.bs.collapse', function () {
            $("#btnFilter").text("");
            var txt1 = "<!--<span class='glyphicon glyphicon-filter'></span>-->隐藏更多条件";
            $("#btnFilter").append(txt1);
        })

        $('#queryHiddenDiv').on('hide.bs.collapse', function () {
            $("#btnFilter").text("");
            var txt1 = "<!--<span class='glyphicon glyphicon-filter'></span>-->显示更多条件";
            $("#btnFilter").append(txt1);
        })

    })

</script>

</body>
</html>